export const mixins = {
  data() {
    return {
      editorOption: {
        modules: {
          toolbar: [
            ['bold', 'italic', 'underline', 'strike'], // 加粗，斜体，下划线，删除线
            ['blockquote', 'code-block'], // 引用，代码块
            [{
              'header': 1
            }, {
              'header': 2
            }], // 标题，键值对的形式；1、2表示字体大小
            [{
              'list': 'ordered'
            }, {
              'list': 'bullet'
            }], // 列表
            [{
              'script': 'sub'
            }, {
              'script': 'super'
            }], // 上下标
            [{
              'indent': '-1'
            }, {
              'indent': '+1'
            }], // 缩进
            [{
              'direction': 'rtl'
            }], // 文本方向
            [{
              'size': ['small', false, 'large', 'huge']
            }], // 字体大小
            [{
              'header': [1, 2, 3, 4, 5, 6, false]
            }], // 几级标题
            [{
              'color': []
            }, {
              'background': []
            }], // 字体颜色，字体背景颜色
            [{
              'align': []
            }], // 对齐方式
            ['clean'], // 清除字体样式
            ['image', 'video'] // 上传图片、上传视频
          ]
        },
        placeholder: '输入内容...'
      },
      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      }
    }
  },
  methods: {
    getOneDay() {
      let now = new Date()
      now = now.toISOString().split('T')[0]
      return [now, now]
    },
    // 获取本周第一天和最后一天
    getWeekRange() {
      const now = new Date()
      const dayOfWeek = now.getDay() // 1...7
      let firstDayOfWeek
      let lastDayOfWeek

      if (dayOfWeek === 0) { // 如果是周日
        firstDayOfWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 6)
        lastDayOfWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate())
      } else {
        firstDayOfWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - dayOfWeek + 1)
        lastDayOfWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() + (7 - dayOfWeek))
      }
      const firstDayStr = firstDayOfWeek.toISOString().split('T')[0]

      const lastDayStr = lastDayOfWeek.toISOString().split('T')[0]
      return [firstDayStr, lastDayStr]
    }
  }
}
